home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / modelers / geomview / source.lha / Geomview / src / lib / geometry / transform3 / tm3adjoint.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-18  |  2.9 KB  |  122 lines

  1. /* Copyright (c) 1992 The Geometry Center; University of Minnesota
  2.    1300 South Second Street;  Minneapolis, MN  55454, USA;
  3.    
  4. This file is part of geomview/OOGL. geomview/OOGL is free software;
  5. you can redistribute it and/or modify it only under the terms given in
  6. the file COPYING, which you should have received along with this file.
  7. This and other related software may be obtained via anonymous ftp from
  8. geom.umn.edu; email: software@geom.umn.edu. */
  9.  
  10. /* Authors: Charlie Gunn, Pat Hanrahan, Stuart Levy, Tamara Munzner, Mark Phillips */
  11.  
  12. #include "transform3.h"
  13.  
  14. #define det( a1, a2, a3, b1, b2, b3, c1, c2, c3 ) \
  15.     (a1*(b2*c3-c2*b3) - a2*(b1*c3-c1*b3) + a3*(b1*c2-c1*b2))
  16.  
  17. static
  18. float 
  19. cofactor( T, x, y )
  20.     Tm3Coord T[4][4];
  21.     int x, y;
  22. {
  23.     static Tm3Coord mat3x3[3][3];
  24.     register Tm3Coord *dst = mat3x3[0];
  25.     register Tm3Coord *src = T[0];
  26.     int i;
  27.  
  28.     for( i=0; i<4; i++, src += 4 ) {
  29.     if(i == x)
  30.         continue;
  31.     if(y != 0) *dst++ = src[0];
  32.     if(y != 1) *dst++ = src[1];
  33.     if(y != 2) *dst++ = src[2];
  34.     if(y != 3) *dst++ = src[3];
  35.     }
  36.     return det( mat3x3[0][0], mat3x3[0][1], mat3x3[0][2],
  37.                 mat3x3[1][0], mat3x3[1][1], mat3x3[1][2],
  38.                 mat3x3[2][0], mat3x3[2][1], mat3x3[2][2] );
  39. }
  40.  
  41.  
  42. static
  43. void
  44. adjoint( T, Tadj )
  45.     Transform3 T, Tadj;
  46. {
  47.     register int x, y;
  48.     float cof;
  49.  
  50.     for( x=0; x<4; x++ )
  51.     for( y=0; y<4; y++ ) {
  52.         cof = cofactor( T, y, x );
  53.         Tadj[x][y] = ((x+y)&1) ? -cof : cof;
  54.     }
  55. }
  56.  
  57. /*-----------------------------------------------------------------------
  58.  * Function:    Tm3Adjoint
  59.  * Description:    compute the adjoint of a transform
  60.  * Args:    T: the transform (INPUT)
  61.  *        Tadj: the adjoint of T (OUTPUT)
  62.  * Returns:    nothing
  63.  * Author:    hanrahan, mbp
  64.  * Date:    Thu Aug  8 15:38:56 1991
  65.  * Notes:    
  66.  */
  67. void
  68. Tm3Adjoint( T, Tadj )
  69.     Transform3 T, Tadj;
  70. {
  71.     if( T == Tadj ) {
  72.     Transform3 Ttmp;
  73.  
  74.     adjoint( T, Ttmp );
  75.     Tm3Copy( Ttmp, Tadj );
  76.     }
  77.     else
  78.     adjoint( T, Tadj );
  79. }
  80.  
  81. /*-----------------------------------------------------------------------
  82.  * Function:    determinant
  83.  * Description:    compute the determinant of a transform, using an already
  84.  *          computed adjoint transform
  85.  * Args:    T: the transform (INPUT)
  86.  *        Tadj: T's adjoint transform (INPUT)
  87.  * Returns:    det(T)
  88.  * Author:    hanrahan, mbp
  89.  * Date:    Thu Aug  8 15:23:53 1991
  90.  * Notes:    
  91.  */
  92. static
  93. float
  94. determinant( T, Tadj )
  95.     Transform3 T, Tadj;
  96. {
  97.     return T[0][0]*Tadj[0][0] 
  98.         + T[0][1]*Tadj[1][0] 
  99.         + T[0][2]*Tadj[2][0] 
  100.         + T[0][3]*Tadj[3][0];
  101. }
  102.  
  103. /*-----------------------------------------------------------------------
  104.  * Function:    Tm3Determinant
  105.  * Description:    compute the determinant of a transform
  106.  * Args:    T: the transform (INPUT)
  107.  * Returns:    det(T)
  108.  * Author:    mbp
  109.  * Date:    Thu Aug  8 15:27:52 1991
  110.  * Notes:    
  111.  */
  112. float
  113. Tm3Determinant( T )
  114.     Transform3 T;
  115. {
  116.     Transform3 Tadj;
  117.  
  118.     Tm3Adjoint( T, Tadj );
  119.  
  120.     return determinant( T, Tadj );
  121. }
  122.